<template>
  <a-card :bordered="false">
    <h3>用户尺码</h3>
    <UserSizeFilter
      ref="filter"
      @onExport="onExport"
      @onSearch="onSearch"
    ></UserSizeFilter>
    <s-table ref="table" bordered size="default" :rowKey="record => record.id" :columns="columns" :data="loadData" :pagination="paginationProps" :scroll="{ x: 1300 }">
      <span slot="defaultRole" slot-scope="text, record">
        <span v-if="record.defaultRole == 1">是</span>
        <span v-if="record.defaultRole == 2">否</span>
      </span>
    </s-table>
  </a-card>
</template>
<script>
import { userFigure, userFigureExport } from '@/api/micromall/sizeRecommendation'
import { STable } from '@/views/box/components'
import UserSizeFilter from '../components/UserSizeFilter'
import { columns } from './userSize.js'
import qs from 'qs'

export default {
  components: {
    UserSizeFilter,
    STable
  },
  data() {
    return {
      columns,
      paginationProps: {
        total: 0,
        showTotal: total => `共有 ${total} 条数据`
        // onShowSizeChange: (current, pageSize) => this.changePageSize(current, pageSize)
      },
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const data = {
          ...this.queryParam,
          current: parameter.pageNo,
          size: parameter.pageSize
        }
        return userFigure(data).then(res => {
          if (res.code === 200) {
            const { records, total, size, current } = res.data
            const data = {
              page: {
                count: total,
                pageNo: current,
                pageSize: size,
                pages: Math.ceil(total / size)
              },
              data: records
            }
            return data
          } else {
            this.$message.error(res.msg || res.message)
            const data = {
              page: {
                count: 0,
                pageNo: 0,
                pages: 0
              },
              data: []
            }
            return data
          }
        })
      }
    }
  },
  created() {
  },
  computed: {},
  mounted() {},
  activated() {
  },
  watch: {
  },
  methods: {
    // 导出查询结果
    onExport() {
      window.location.href =  userFigureExport + `?${qs.stringify(this.queryParam)}`
    },

    //查询
    onSearch(obj) {
      console.log(obj, 'obj')
      this.queryParam = obj
      this.$refs.table.refresh(true)
    }
  }
}
</script>
<style lang="less" scoped>
</style>
